﻿using BLL;
using gfLibrary;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IYAKASAPortal.Standard
{
    public partial class TYPE_FDJ_CONTENT_Insert_Update : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack == false)
            {

                string strMode = Request["m"];

                if ((strMode == "u") || (strMode == "b") || (strMode == "r"))
                {
                    string strId = Request["UniqueKey"];

                    TYPE_FDJ_CONTENT_BLL m_TYPE_FDJ_CONTENT_BLL = new TYPE_FDJ_CONTENT_BLL();

                    if (m_TYPE_FDJ_CONTENT_BLL.Exists(Convert.ToInt32(strId)) == true)
                    {
                        TYPE_FDJ_CONTENT m_TYPE_FDJ_CONTENT = new TYPE_FDJ_CONTENT();
                        m_TYPE_FDJ_CONTENT = m_TYPE_FDJ_CONTENT_BLL.GetModel(Convert.ToInt32(strId));

                        txtID.Text = m_TYPE_FDJ_CONTENT.ID.ToString();
                        txtFDJXH.Text = m_TYPE_FDJ_CONTENT.FDJXH;
                        txtFDJZZC.Text = m_TYPE_FDJ_CONTENT.FDJZZC;
                        txtRLLB.Text = m_TYPE_FDJ_CONTENT.RLLB;
                        txtRYBH.Text = m_TYPE_FDJ_CONTENT.RYBH;
                        txtGYFS.Text = m_TYPE_FDJ_CONTENT.GYFS;
                        txtJQFS.Text = m_TYPE_FDJ_CONTENT.JQFS;
                        txtEDGL.Text = m_TYPE_FDJ_CONTENT.EDGL;
                        txtEDZS.Text = m_TYPE_FDJ_CONTENT.EDZS;
                        txtEDNJZS.Text = m_TYPE_FDJ_CONTENT.EDNJZS;
                        txtEDNJ.Text = m_TYPE_FDJ_CONTENT.EDNJ;
                        txtEDYH.Text = m_TYPE_FDJ_CONTENT.EDYH;
                        txtFDJPL.Text = m_TYPE_FDJ_CONTENT.FDJPL;
                        txtFDJGS.Text = m_TYPE_FDJ_CONTENT.FDJGS;
                        txtFDJCC.Text = m_TYPE_FDJ_CONTENT.FDJCC;
                    }
                    else
                    {
                        gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "请选择一条记录！");
                        gfAjaxJs.SetGoToUrl(this.UpdatePanel1, "TYPE_FDJ_CONTENT_List.aspx");
                    }

                    if ((strMode == "b") || (strMode == "r"))
                    {
                        txtID.ReadOnly = true;
                        txtID.CssClass = "csstextboxreadonly";
                        txtFDJXH.ReadOnly = true;
                        txtFDJXH.CssClass = "";
                        txtFDJZZC.ReadOnly = true;
                        txtFDJZZC.CssClass = "csstextboxreadonly";
                        txtRLLB.ReadOnly = true;
                        txtRLLB.CssClass = "csstextboxreadonly";
                        txtRYBH.ReadOnly = true;
                        txtRYBH.CssClass = "csstextboxreadonly";
                        txtGYFS.ReadOnly = true;
                        txtGYFS.CssClass = "csstextboxreadonly";
                        txtJQFS.ReadOnly = true;
                        txtJQFS.CssClass = "csstextboxreadonly";
                        txtEDGL.ReadOnly = true;
                        txtEDGL.CssClass = "csstextboxreadonly";
                        txtEDZS.ReadOnly = true;
                        txtEDZS.CssClass = "csstextboxreadonly";
                        txtEDNJZS.ReadOnly = true;
                        txtEDNJZS.CssClass = "csstextboxreadonly";
                        txtEDNJ.ReadOnly = true;
                        txtEDNJ.CssClass = "csstextboxreadonly";
                        txtEDYH.ReadOnly = true;
                        txtEDYH.CssClass = "csstextboxreadonly";
                        txtFDJPL.ReadOnly = true;
                        txtFDJPL.CssClass = "csstextboxreadonly";
                        txtFDJGS.ReadOnly = true;
                        txtFDJGS.CssClass = "csstextboxreadonly";
                        txtFDJCC.ReadOnly = true;
                        txtFDJCC.CssClass = "csstextboxreadonly";
                 
                        btnSave.Visible = false;
                    }

                    if (strMode == "r")
                    {
                        btnBack.Visible = false;
                    }
                }
                if (strMode == "i")
                {
                    lblOperateType.Text = "添加";
                }
                if (strMode == "b" || strMode == "r")
                {
                    lblOperateType.Text = "查看";
                }
                if (strMode == "u")
                {
                    lblOperateType.Text = "修改";
                }
            }

            //btnBack.Attributes["onclick"] = "javascript:window.location.href='TYPE_FDJ_CONTENT_List.aspx';return false;";
            btnBack.Attributes["onclick"] = "window.history.back()";

        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strID = txtID.Text.Trim();
            string strFDJXH = txtFDJXH.Text.Trim();
            string strFDJZZC = txtFDJZZC.Text.Trim();
            string strRLLB = txtRLLB.Text.Trim();
            string strRYBH = txtRYBH.Text.Trim();
            string strGYFS = txtGYFS.Text.Trim();
            string strJQFS = txtJQFS.Text.Trim();
            string strEDGL = txtEDGL.Text.Trim();
            string strEDZS = txtEDZS.Text.Trim();
            string strEDNJZS = txtEDNJZS.Text.Trim();
            string strEDNJ = txtEDNJ.Text.Trim();
            string strEDYH = txtEDYH.Text.Trim();
            string strFDJPL = txtFDJPL.Text.Trim();
            string strFDJGS = txtFDJGS.Text.Trim();
            string strFDJCC = txtFDJCC.Text.Trim();



            TYPE_FDJ_CONTENT m_TYPE_FDJ_CONTENT = new TYPE_FDJ_CONTENT();
            TYPE_FDJ_CONTENT_BLL m_TYPE_FDJ_CONTENT_BLL = new TYPE_FDJ_CONTENT_BLL();

            m_TYPE_FDJ_CONTENT.FDJXH =strFDJXH;
            m_TYPE_FDJ_CONTENT.FDJZZC=strFDJZZC;
            m_TYPE_FDJ_CONTENT.RLLB=strRLLB;
            m_TYPE_FDJ_CONTENT.RYBH=strRYBH;
            m_TYPE_FDJ_CONTENT.GYFS=strGYFS;
            m_TYPE_FDJ_CONTENT.JQFS=strJQFS;
            m_TYPE_FDJ_CONTENT.EDGL=strEDGL;
            m_TYPE_FDJ_CONTENT.EDZS=strEDZS;
            m_TYPE_FDJ_CONTENT.EDNJZS=strEDNJZS;
            m_TYPE_FDJ_CONTENT.EDNJ=strEDNJ;
            m_TYPE_FDJ_CONTENT.EDYH=strEDYH;
            m_TYPE_FDJ_CONTENT.FDJPL=strFDJPL;
            m_TYPE_FDJ_CONTENT.FDJGS=strFDJGS;
            m_TYPE_FDJ_CONTENT.FDJCC=strFDJCC;

            if (string.IsNullOrEmpty(strID) == true)
            {
                strID = "-1";
            }

            if (m_TYPE_FDJ_CONTENT_BLL.Exists(Convert.ToInt32(strID)) == false)
            {
                //m_TYPE_FDJ_CONTENT.ID = m_TYPE_FDJ_CONTENT_BLL.GetMax_ID();

                if (m_TYPE_FDJ_CONTENT_BLL.Insert(m_TYPE_FDJ_CONTENT) == true)
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "新增成功！");
                    txtID.Text = m_TYPE_FDJ_CONTENT.ID.ToString();
                }
                else
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "新增失败！");
                }
            }
            else
            {
                if (m_TYPE_FDJ_CONTENT_BLL.Update(m_TYPE_FDJ_CONTENT, Convert.ToInt32(strID)) == true)
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "更新成功！");
                }
                else
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "更新失败！");
                }
            }
        }
    }
}